/*
 *  Copyright 2012 SerGenis. All rights reserved.
 */
package com.sergenis.swing;

import java.awt.Dimension;
import java.awt.Toolkit;

/**
 *
 * @author SerGenis
 */
public class SwingUtil {

    public static void centerOnScreen(java.awt.Window window) {
	window.pack();
	centerOnScreenX(window);
    }

    public static void centerOnScreen(java.awt.Dialog dialog) {
	dialog.pack();
	centerOnScreenX(dialog);
    }

    public static void centerOnScreen(java.awt.Frame frame) {
	frame.pack();
	centerOnScreenX(frame);
    }

    static void centerOnScreenX(java.awt.Component component) {
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	Dimension dialogSize = component.getSize();
	component.setLocation((screenSize.width / 2) - (dialogSize.width / 2),
	    (screenSize.height / 2) - (dialogSize.height / 2));
    }
}
